package org.deltaset.faces;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

/**
 *
 * @author Dimitar Makariev
 */
public class TracePhaseListener implements PhaseListener {

    private static final long serialVersionUID = 1230032804429003338L;
    private static final Logger log = Logger.getLogger(TracePhaseListener.class.getName());
    private long startTime;

    @Override
    public void afterPhase(PhaseEvent event) {
        log.log(Level.WARNING, "afterPhase {0}  time={1}ms", new Object[]{event.getPhaseId(), System.currentTimeMillis() - startTime});
    }

    @Override
    public void beforePhase(PhaseEvent event) {
        if (event.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {
            startTime = System.currentTimeMillis();
        }
        log.log(Level.WARNING, "beforePhase {0}", event.getPhaseId());
    }

    @Override
    public PhaseId getPhaseId() {
        return PhaseId.ANY_PHASE;
    }
}
